import { del, download, get } from "@/utils/request";
import { fileListRes } from "./types";
enum URL {
	// 获取用户文件列表
	getUserFileList = "/file/upload/queryDirByUser",
	getqueryDirs = "/file/upload/queryDirs",
	// 根据用户文件tif，获取详情
	getUserFileDetail = "/file/upload",
	// 更新数据
	refreshData = "/file/upload/freshDir",
	downloadData = "/common/download/ftp",
	queryByKeywords = "file/upload/queryByKeywords",
	getoptionbyId = "/analysis/getColumn",
	vecAnalysis = "/analysis/areaCount",
	analysShp = "/analysis/doAnalysis",
	getCountColumn = "/analysis/getCountColumn",
	queryShpService = "/analysis/queryShpService",
	countTable = "/analysis/countTable",
	analysisResult = "/analysis/compareAnalysis",
	getcity = "/common/getCitys",
	getqu = "/common/getDistrict",
	queryletaData = "/file/upload/queryMetaData",
	queryImageService = "/analysis/queryImageService",
}

const getUserFileDetail = async (fileId: number) =>
	get<any>({ url: URL.getUserFileDetail + "/" + fileId });
const getqueryDirs = async (parentPath: string) =>
	get<fileListRes>({
		url: URL.getqueryDirs,
		params: {
			parentPath,
		},
	});
const getUserFileList = async (userCode: string, showGeo: boolean, keywords?: string) =>
	get<fileListRes>({
		url: URL.getUserFileList,
		params: {
			userCode,
			showGeo,
			keywords,
		},
	});
const refreshData = async (userCode: string) =>
	get<any>({ url: URL.refreshData, params: { userCode } });
const downloadData = async (filePath: string) =>
	download({
		url: URL.downloadData,
		params: {
			filePath,
		},
	});

const deleteData = async (fileId: string) =>
	del<any>({
		url: URL.getUserFileDetail + "/" + fileId,
	});

const queryData = async (keywords: string) =>
	get<any>({ url: URL.queryByKeywords, params: { keywords } });
const queryOptionById = async (id: string) => get<any>({ url: URL.getoptionbyId, params: { id } });
const getCitybycode = async (pCode: string) => get<any>({ url: URL.getcity, params: { pCode } });
const getvectorAnalysis = async (taskId: string) =>
	get<any>({ url: URL.vecAnalysis, params: { taskId } });
const getqubycode = async (cCode: string) => get<any>({ url: URL.getqu, params: { cCode } });
const getCountColumn = async (id: string) => get<any>({ url: URL.getCountColumn, params: { id } });
// const getShpService = async (id: string) => get<any>({ url: URL.queryShpService, params: { id } });
const getcountTable = async (leftShpId: string, rightShpId: string) =>
	get<fileListRes>({
		url: URL.countTable,
		params: {
			leftShpId,
			rightShpId,
		},
	});
const getAnalysisResult = async (leftShpId: string, rightShpId: string) =>
	get<fileListRes>({
		url: URL.analysisResult,
		params: {
			leftShpId,
			rightShpId,
		},
	});
const getShpService = async (userCode: string, showGeo: boolean, keywords?: string) =>
	get<fileListRes>({
		url: URL.queryShpService,
		params: {
			userCode,
			showGeo,
			keywords,
		},
	});
const queryImageService = async (userCode: string, showGeo: boolean, keywords?: string) =>
	get<fileListRes>({
		url: URL.queryImageService,
		params: {
			userCode,
			showGeo,
			keywords,
		},
	});
const getqueryletaData = async (filePath: string) =>
	get<fileListRes>({
		url: URL.queryletaData,
		params: {
			filePath,
		},
	});
const analysByShp = async (
	id: string,
	countField: string,
	countType: string,
	sortField: string,
	wkt: string
) =>
	get<any>({
		url: URL.analysShp,
		params: {
			id,
			countField,
			countType,
			sortField,
			wkt,
		},
	});

export {
	getUserFileList,
	getqueryDirs,
	getUserFileDetail,
	refreshData,
	downloadData,
	deleteData,
	queryData,
	queryOptionById,
	analysByShp,
	getCitybycode,
	getqubycode,
	getvectorAnalysis,
	getCountColumn,
	getShpService,
	getcountTable,
	getAnalysisResult,
	getqueryletaData,
	queryImageService,
};
